package StudyCode.summary.mycollection;

import java.lang.reflect.Array;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ItTakesAnArrayAndAddTheSpecifiedElementToTheEndOfTheIt {
	public static <T> T[] addElement(Class<T> typeClass, T[] array,
	                                 T element) {
		@SuppressWarnings("unchecked")
		T[] newArray = (T[]) Array.newInstance(typeClass, array.length + 1);
		int i = 0;
		while (i < array.length) {
			newArray[i] = array[i];
			i++;
		}
		newArray[i] = element;

		return newArray;
	}
}
